package cn.blbsz.shop.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.provider.HibernateUtils;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.SessionFactoryUtils;

import cn.blbsz.shop.utils.Snowflake;

/**
 * Created by Lenovo on 2017/3/31.
 */
@Configuration
@EnableConfigurationProperties(SmsProperties.class)
public class AppConfig {

	@Bean
	public Snowflake snowflake() {
		return new Snowflake(1);
	}

	@Autowired
	private SmsProperties smsProperties;

	@Bean
	public IAcsClient defaultAcsClient(){
		IClientProfile profile = DefaultProfile.getProfile(smsProperties.getRegionId(), smsProperties.getAccessKeyId(), smsProperties.getSecret());
		try {
			DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Sms",  "sms.aliyuncs.com");
		} catch (ClientException e) {
			e.printStackTrace();
		}
		return new DefaultAcsClient(profile);
	}

}
